import 'package:gameplay_flutter/lib_basemodel/chat_room/chat/hb_message_type.dart';

import '../../../lib_basemodel/chat_room/chat/chat_content.dart';
import '../../../lib_basemodel/chat_room/chat/message.dart';

import '../../../lib_rtc/socket/jr_socket.dart';
import '../../../lib_runtime/logger.dart';
import '../interface/room_page_model.dart';
import '../msg/room_msg.dart';

/// 处理房间公屏消息，普通消息、卡片消息
class RoomChatMsgHandler with SocketMsgHandler {
  final RoomPageModel roomModel;

  RoomChatMsgHandler(this.roomModel);

  @override
  HBMessageType get msgType => HBMessageType.chatRoomOpenMsg;

  String get channel =>
      (roomModel.roomModel.roomTokenBean?.channel!).toString();

  // static RoomMsg unpackChatMsg(Message msg) {
  //   // if (msg.type == MessageTypeEnum.text) {
  //   //   return RoomMsg<ChatContent>(msg, ChatContent());
  //   // } else {
  //   //   // return RoomMsg<CardChatContent>(msg, CardChatContent());
  //   // }

  //   return RoomMsg(chatContent: );
  // }

  @override
  handleMsg(ChatContent msg) {
    RoomMsg unpackedMsg = RoomMsg(chatContent: msg);
    // roomModel.channel?.freePublicChat != true &&
    if ((unpackedMsg.chatContent?.senderUser?.id ?? 0) > 0) {
      RLog.d('Free chat not enable, discard msg: ${msg.senderUser?.id}');
      return;
    }
    roomModel.barrageListModel.addMsg(unpackedMsg);
  }
}
